package com.it.flowable.controller;

import com.it.flowable.common.vo.common.CommonResult;
import com.it.flowable.service.leave.main.LeaveMainService;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/leave")
public class BpmLeaveController {

    @Resource
    private LeaveMainService leaveMainService;

    /**
     * 请假申请
     *
     * @param reqMap
     * @return
     */
    @PostMapping("/apply")
    public CommonResult submitLeaveApply(@RequestBody Map<String, Object> reqMap) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        请假超过3天
//        map.put("cDays", 5);
//        map.put("cAppCde", "2412005");
//        map.put("cAppRmk", "申请休假5天");

//        请假不超过3天
//        map.put("cDays", 3);
//        map.put("cAppCde", "2412005");
//        map.put("cAppRmk", "申请休假3天");

        // 重新提交申请时的额外参数
//        reqMap.put("isReApply", "1");
//        reqMap.put("isCancelApply", "1"); // 取消申请时传值
//        reqMap.put("cTaskId", "");//
        return leaveMainService.submitApply(reqMap);
    }

    /**
     * 提交一级审核
     *
     * @param reqMap
     * @return
     */
    @PostMapping("/firstChk")
    public CommonResult submitFirstChk(@RequestBody Map<String, Object> reqMap) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        reqMap.put("cTaskId", "");
//        reqMap.put("cFirstChkOpn", "");
//        reqMap.put("cFirstChkRmk", "");
//        reqMap.put("cFirstChkCde", "");
        return leaveMainService.submitFirstChk(reqMap);
    }

    /**
     * 提交二级审核
     *
     * @param reqMap
     * @return
     */
    @PostMapping("/secondChk")
    public CommonResult submitSecondChk(@RequestBody Map<String, Object> reqMap) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        reqMap.put("cTaskId", "");
//        reqMap.put("cSecondChkOpn", "");
//        reqMap.put("cSecondChkRmk", "");
//        reqMap.put("cSecondChkCde", "");
        return leaveMainService.submitSecondChk(reqMap);
    }

    /** ======================== 辅助流程操作 ========================*/
    /**
     * 编辑任务状态：解除接收、已接收等
     *
     * @param reqMap
     * @return
     */
    @PostMapping("/editTask")
    public CommonResult editTask(@RequestBody Map<String, Object> reqMap) {
//        Map<String, Object> map = new HashMap<String, Object>();
//        reqMap.put("cMainId", "");
//        reqMap.put("cTaskId", "");
//        reqMap.put("cTaskNo", "");
//        reqMap.put("cTaskType", "");
//        reqMap.put("taskStatus", "");// 接收、解除接收、挂起等枚举
//        reqMap.put("cOwnerId", "");
        return leaveMainService.editTask(reqMap);
    }

    /**
     * 生成流程图
     * @param response
     * @param processId 流程ID：ACT_LEAVE_PROCESS_EXT 通过cMainId去找
     */
    @GetMapping("/pic/{processId}")
    public void showPic(HttpServletResponse response, @PathVariable("processId") String processId) {
        leaveMainService.showPic(response, processId);
    }

}
